package com.tlx.util;

import java.net.URL;

public class CmdUtils {

    public static void exec(String cmd) {
        try {
            Runtime.getRuntime().exec(cmd);
            // Process proc = Runtime.getRuntime().exec(cmd);
            // InputStream err = proc.getErrorStream();
            // Reader rerr = IoUtil.getReader(err, "utf-8");
            // String errStr = IoUtil.read(rerr);
            // IoUtil.close(rerr);
            // if (StrUtil.isNotBlank(errStr)) {
            // throw new RuntimeException(errStr + "\n执行命令出错：" + cmd);
            // }
        } catch (Exception e) {
            throw new RuntimeException("执行命令出错：" + cmd, e);
        }
    }

    public static void operUrl(String urlStr) {
        URL url = null;
        try {
            url = new URL(urlStr);
        } catch (Exception e) {
            throw new RuntimeException("URL地址错误：" + urlStr);
        }
        exec("rundll32 url.dll,FileProtocolHandler " + url);
    }
}
